home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2001 May / SGI IRIX Base Documentation 2001 May.iso / usr / share / catman / p_man / cat3 / librw / RWCRegexp.z / RWCRegexp
Encoding:
Text File  |  1998-10-30  |  10.5 KB  |  265 lines

  1.  
  2.  
  3.  
  4. RRRRWWWWCCCCRRRReeeeggggeeeexxxxpppp((((3333CCCC++++++++))))                                                RRRRWWWWCCCCRRRReeeeggggeeeexxxxpppp((((3333CCCC++++++++))))
  5.  
  6.  
  7.  
  8. NNNNaaaammmmeeee
  9.      RWCRegexp - Rogue Wave library class
  10.  
  11. SSSSyyyynnnnooooppppssssiiiissss
  12.               #include <rw/regexp.h>
  13.  
  14.  
  15.  
  16.               RWCRegexp re(".*\.doc");// Matches filename with suffix ".doc"
  17.  
  18.  
  19.  
  20.  
  21. DDDDeeeessssccccrrrriiiippppttttiiiioooonnnn
  22.      Class RRRRWWWWCCCCRRRReeeeggggeeeexxxxpppp represents a regular expression.  The constructor
  23.      "compiles" the expression into a form that can be used more efficiently.
  24.      The results can then be used for string searches using class RRRRWWWWCCCCSSSSttttrrrriiiinnnngggg.
  25.      TTTThhhheeee rrrreeeegggguuuullllaaaarrrr eeeexxxxpppprrrreeeessssssssiiiioooonnnn ((((RRRREEEE)))) iiiissss ccccoooonnnnssssttttuuuucccctttteeeedddd aaaassss ffffoooolllllllloooowwwwssss::::  The following
  26.      rules determine one-character REs that match a ssssiiiinnnngggglllleeee character:
  27.  
  28.      1.1 Any character that is not a special character (to be defined) matches
  29.      itself.
  30.  
  31.      1.2 A backslash (\\\\ffffRRRR)))) ffffoooolllllllloooowwwweeeedddd bbbbyyyy aaaannnnyyyy ssssppppeeeecccciiiiaaaallll cccchhhhaaaarrrraaaacccctttteeeerrrr mmmmaaaattttcccchhhheeeessss tttthhhheeee
  32.      lllliiiitttteeeerrrraaaallll cccchhhhaaaarrrraaaacccctttteeeerrrr iiiittttsssseeeellllffff....  IIII....eeee...., this "escapes" the special character.
  33.  
  34.      1.3 The "special characters" are:
  35.  
  36.                         ++++     ****     ????     ....     [[[[     ]]]]     ^^^^     $$$$
  37.  
  38.  
  39.  
  40.      1.4 The period (....) matches any character except the newline.  EEEE....gggg....,
  41.      "....uuuummmmppppttttyyyy" matches either "HHHHuuuummmmppppttttyyyy" or "DDDDuuuummmmppppttttyyyy...."
  42.  
  43.      1.5 A set of characters enclosed in brackets ([[[[]]]]) is a one-character RE
  44.      that matches any of the characters in that set.  EEEE....gggg...., "[[[[aaaakkkkmmmm]]]]" matches
  45.      either an "aaaa", "kkkk", or "mmmm".  A range of characters can be indicated with
  46.      a dash.  EEEE....gggg...., "[[[[aaaa----zzzz]]]]" matches any lower-case letter.  However, if the
  47.      first character of the set is the caret (^^^^), then the RE matches any
  48.      character eeeexxxxcccceeeepppptttt those in the set.  It does nnnnooootttt match the empty string.
  49.      Example: [[[[^^^^aaaakkkkmmmm]]]] matches any character eeeexxxxcccceeeepppptttt  "aaaa", "kkkk", or "mmmm".  The
  50.      caret loses its special meaning if it is not the first character of the
  51.      set.  The following rules can be used to build a multicharacter RE.
  52.  
  53.      2.1 A one-character RE followed by an asterisk (****) matches zzzzeeeerrrroooo or more
  54.      occurrences of the RE.  Hence, [[[[aaaa----zzzz]]]]**** matches zero or more lower-case
  55.      characters.
  56.  
  57.      2.2 A one-character RE followed by a plus (++++) matches oooonnnneeee or more
  58.      occurrences of the RE.  Hence, [[[[aaaa----zzzz]]]]++++ matches one or more lower-case
  59.      characters.
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. RRRRWWWWCCCCRRRReeeeggggeeeexxxxpppp((((3333CCCC++++++++))))                                                RRRRWWWWCCCCRRRReeeeggggeeeexxxxpppp((((3333CCCC++++++++))))
  71.  
  72.  
  73.  
  74.      2.3 A question mark (????) is an optional element.  The preceeding RE can
  75.      occur zero or once in the string -- no more.  EEEE....gggg.... xxxxyyyy????zzzz matches either
  76.      xxxxyyyyzzzz or xxxxzzzz.
  77.  
  78.      2.4 The concatenation of REs is a RE that matches the corresponding
  79.      concatenation of strings.  EEEE....gggg...., [A-Z][a-z]* matches any capitalized
  80.      word.  Finally, the entire regular expression can be anchored to match
  81.      only the beginning or end of a line:
  82.  
  83.      3.1 If the caret (^^^^) is at the beginning of the RE, then the matched
  84.      string must be at the beginning of a line.
  85.  
  86.      3.2 If the dollar sign ($$$$) is at the end of the RE, then the matched
  87.      string must be at the end of the line.  The following escape codes can be
  88.      used to match control characters:
  89.  
  90.  
  91.      backspace
  92.  
  93.      \\\\ EEEESSSSCCCC (escape)
  94.  
  95.  
  96.      ffffoooorrrrmmmmffffeeeeeeeedddd
  97.  
  98.  
  99.      nnnneeeewwwwlllliiiinnnneeee
  100.  
  101.       ccccaaaarrrrrrrriiiiaaaaggggeeee rrrreeeettttuuuurrrrnnnn
  102.  
  103.       ttttaaaabbbb
  104.  
  105.      dddd tttthhhheeee lllliiiitttteeeerrrraaaallll hhhheeeexxxx nnnnuuuummmmbbbbeeeerrrr 0000xxxxdddddddd
  106.  
  107.      dddddddd tttthhhheeee lllliiiitttteeeerrrraaaallll ooooccccttttaaaallll nnnnuuuummmmbbbbeeeerrrr dddddddddddd
  108.  
  109.      CCCC CCCCoooonnnnttttrrrroooollll ccccooooddddeeee....  EEEE....gggg.... \fB^D iiiissss """"ccccoooonnnnttttrrrroooollll----DDDD""""
  110.  
  111. PPPPeeeerrrrssssiiiisssstttteeeennnncccceeee
  112.      None
  113.  
  114. EEEExxxxaaaammmmpppplllleeee
  115.               #include <rw/regexp.h>
  116.           #include <rw/cstring.h>
  117.           #include <rw/rstream.h>
  118.           main(){
  119.             RWCString aString("Hark! Hark! the lark");
  120.             // A regular expression matching any lower-case word
  121.             // starting with "l":
  122.             RWCRegexp reg("l[a-z]*");
  123.             cout << aString(reg) << endl;  // Prints "lark"
  124.           }
  125.  
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. RRRRWWWWCCCCRRRReeeeggggeeeexxxxpppp((((3333CCCC++++++++))))                                                RRRRWWWWCCCCRRRReeeeggggeeeexxxxpppp((((3333CCCC++++++++))))
  137.  
  138.  
  139.  
  140. PPPPuuuubbbblllliiiicccc CCCCoooonnnnssssttttrrrruuuuccccttttoooorrrrssss
  141.               RRRRWWWWCCCCRRRReeeeggggeeeexxxxpppp(const char* pat);
  142.  
  143.  
  144.      Construct a regular expression from the pattern given by ppppaaaatttt.  The status
  145.      of the results can be found by using member function ssssttttaaaattttuuuussss(((()))).
  146.  
  147.               RRRRWWWWCCCCRRRReeeeggggeeeexxxxpppp(const RWCRegexp& r);
  148.  
  149.  
  150.      Copy constructor.  Uses value semantics -- self will be a copy of rrrr.
  151.  
  152. PPPPuuuubbbblllliiiicccc DDDDeeeessssttttrrrruuuuccccttttoooorrrr
  153.               ~RRRRWWWWCCCCRRRReeeeggggeeeexxxxpppp();
  154.  
  155.  
  156.      Destructor.  Releases any allocated memory.
  157.  
  158. AAAAssssssssiiiiggggnnnnmmmmeeeennnntttt OOOOppppeeeerrrraaaattttoooorrrrssss
  159.               RWCRegexp&
  160.           ooooppppeeeerrrraaaattttoooorrrr====(const RWCRegexp&);
  161.  
  162.  
  163.      Uses value semantics -- sets self to a copy of rrrr.
  164.  
  165.               RWCRegexp&
  166.           ooooppppeeeerrrraaaattttoooorrrr====(const char* pat);
  167.  
  168.  
  169.      Recompiles self to the pattern given by ppppaaaatttt.  The status of the results
  170.      can be found by using member function ssssttttaaaattttuuuussss(((()))).
  171.  
  172. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr FFFFuuuunnnnccccttttiiiioooonnnnssss
  173.               size_t
  174.           iiiinnnnddddeeeexxxx(const RWCString& str,size_t* len, size_t start=0) const;
  175.  
  176.  
  177.      Returns the index of the first instance in the string ssssttttrrrr that matches
  178.      the regular expression compiled in self, or RRRRWWWW____NNNNPPPPOOOOSSSS if there is no such
  179.      match.  The search starts at index ssssttttaaaarrrrtttt.  The length of the matching
  180.      pattern is returned in the variable pointed to by lllleeeennnn.  If an invalid
  181.      regular expression is used for the search, an exception of type
  182.      RRRRWWWWIIIInnnntttteeeerrrrnnnnaaaallllEEEErrrrrrrr will be thrown.  Note that this member function is
  183.      relatively clumsy to use -- class RRRRWWWWCCCCSSSSttttrrrriiiinnnngggg offers a better interface to
  184.      regular expression searches.
  185.  
  186.               statVal
  187.           ssssttttaaaattttuuuussss();
  188.  
  189.  
  190.      Returns the status of the regular expression and resets status to OOOOKKKK:
  191.  
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. RRRRWWWWCCCCRRRReeeeggggeeeexxxxpppp((((3333CCCC++++++++))))                                                RRRRWWWWCCCCRRRReeeeggggeeeexxxxpppp((((3333CCCC++++++++))))
  203.  
  204.  
  205.  
  206.      ssssttttaaaattttVVVVaaaallll MMMMeeeeaaaannnniiiinnnngggg
  207.  
  208.  
  209.      RRRRWWWWCCCCRRRReeeeggggeeeexxxxpppp::::::::OOOOKKKK No errors
  210.  
  211.  
  212.      RRRRWWWWCCCCRRRReeeeggggeeeexxxxpppp::::::::IIIILLLLLLLLEEEEGGGGAAAALLLL Pattern was illegal
  213.  
  214.  
  215.      RRRRWWWWCCCCRRRReeeeggggeeeexxxxpppp::::::::TTTTOOOOOOOOLLLLOOOONNNNGGGG Pattern exceeded maximum length
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.                                                                         PPPPaaaaggggeeee 4444
  262.  
  263.  
  264.  
  265.